package com.cecil.generate.model;


import com.cecil.generate.exception.BusinessException;
import lombok.Data;

@Data
public class Result<T> {

    private Integer code;
    private String msg;
    private T data;

    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(ResultEnum.SUCCESS.value, ResultEnum.SUCCESS.desc, data);
    }

    public static <T> Result<T> success() {
        return success(null);
    }

    public static <T> Result<T> error(String msg) {
        return new Result<>(ResultEnum.ERROR.value, msg, null);
    }

    public static <T> Result<T> error(BusinessException e) {
        return new Result<>(ResultEnum.ERROR.value, e.getMessage(), null);
    }

    public static <T> Result<T> error() {
        return error(ResultEnum.ERROR.desc);
    }
}
